<?php
namespace App\Services\Sms;

use App\Services\ProjectValidate;
/**
 * @Author: Marte
 * @Date:   2017-05-27 16:25:13
 * @Last Modified by:   ws
 * @Last Modified time: 2018-06-12 10:16
 */
class ValidateSms extends ProjectValidate
{
    /**
     * 自定义子类初始化
     * @param array $initData
     * @return mixed
     */
    public function initValidate($initData = [])
    {
       /* if (!empty($initData['app_id'])) {
            $this->rules['app_id']  = 'regex:/^\d+(,\d+)*$/';
        }
        if (!empty($initData['app_id_smsInfo'])) {
            $this->rules['app_id_smsInfo']  = 'required|int|min:1';
        }
        if (!empty($initData['id'])) {
            $this->rules['id']  = 'required|int|min:1';
        }*/


        if(!empty($initData['temp'])) {
            $initData['temp'] == 'smsInfo' && $this->rules = ['app_id' =>  'required|int|min:1'];
            $initData['temp'] == 'smsList' && $this->rules = ['app_id' => 'regex:/^\d+(,\d+)*$/'];
            $initData['temp'] == 'editSms' && $this->rules['id'] = 'required|int|min:1';
        }
      

    }
    
    public $rules = [
        'app_id'         => 'int|min:1',
        'mobile'         => 'regex:/^1[34578][0-9]{9}$/',
        'action'         => 'min:2',
        'id'             => 'int|min:1',
        'sms_info'       => 'array|min:2',
        'text'           => 'string|min:5',
        'is_public'      => 'in:0,1',
        //'msgType'        => 'in(['receive', 'send'])'
        'apikey'         => 'string|max:32',
        'to_user_name'   => 'min:2',
        'page'           => 'int|min:1',
        'listRows'       => 'integer|min:1|max:100'
    ];


    public $messages = [
       
    ];

    /**
     * @var array 上面规则中定义的 key 的名字
     */
    public $attributes = [
      
    ];
}